package mju.cxf.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import mju.cxf.constant.MessageConstant;
import mju.cxf.dto.ActivityDTO;
import mju.cxf.dto.CategoriesDTO;
import mju.cxf.result.Result;
import mju.cxf.service.ActivityService;
import mju.cxf.vo.ActivityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 广告相关接口
 */

@RestController
@RequestMapping("/admin/api/activity")
@Api(tags = "广告接口列表")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    /**
     * 删除广告信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除广告信息", notes = "管理员通过此接口删除广告信息")
    public Result<String> deleteActivity(@PathVariable Integer id) {
        return activityService.deleteActivity(id) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 新建广告信息
     *
     * @param activityDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新建广告")
    public Result<String> createCategories(@RequestBody ActivityDTO activityDTO) {
        return activityService.saveActivity(activityDTO) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 修改广告信息
     *
     * @param activityDTO
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改广告信息")
    public Result<String> updateAdmin(@RequestBody ActivityDTO activityDTO) {
        return activityService.updateActivity(activityDTO) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }

    /**
     * 分页查询广告信息
     * @return 分页查询结果
     */
    @GetMapping("/pages")
    @ApiOperation(value = "分页查询广告信息", notes = "管理员通过此接口分页查询广告信息")
    public Page<ActivityVO> selectPage(@RequestParam(value = "title",required = false) String title,
                                       @RequestParam(value = "type",required = false) String type,
                                       @RequestParam(value = "status",required = false) Integer status,
                                       @RequestParam(value = "current",defaultValue = "1") int current,
                                       @RequestParam(value = "size",defaultValue = "10") int size) {
        return activityService.selectPage(title,type, status, current, size);
    }
}
